/* 

Replication syntax CPS article
"Social change and women's left vote. The role of employment, education, and marriage in the gender vote gap"

Dr. Mathilde M. van Ditmars, University of Lucerne & University of Zurich
Dr. Rosalind Shorrocks, University of Manchester
May 2024 (Stata version 18)

File 4/4. Analyses and graphs
*/

*perform file creation and analyses for tables in designated dofiles per dataset
*then perform analyses below to create figures below


global output "DEFINE"

cd "DEFINE"

global output "DEFINE"


*Figure 1

grc1leg "DE_gendergap_marginsdydx" "CH_gendergap_marginsdydx" "ENG_gendergap_marginsdydx"
graph save "${output}/Figure_1.gph", replace
graph export "${output}/Figure_1.jpg", replace
graph export "${output}/Figure_1.pdf", replace


*GSOEP

do VanDitmars_Shorrocks_Replication_1_GSOEP.do

*FE and BE analyses
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
est store DE_int_fe

xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, be
est store DE_int_be

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.syear, fe vce(cluster pid), if female==1
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store DE_female_fe

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.syear, fe vce(cluster pid), if female==0
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store DE_male_fe

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.syear, be, if female==1
margins,  dydx(work3 edu4 civsta_3) post coeflegend
est store DE_female_be

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.syear, be, if female==0
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store DE_male_be




*transition analysis
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.syear, fe vce(cluster pid)
capture drop sample_trans
gen sample_trans=1 if e(sample)

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans i.reli_c i.kids i.syear, fe vce(cluster pid), if female==1 & sample_trans==1

margins, dydx(civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans) post coeflegend
est store DE_female_trans

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.syear, fe vce(cluster pid), if female==0 & sample_trans==1

margins, dydx(civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans) post coeflegend
est store DE_male_trans

xtreg left_gr civ1_trans##female civ2_trans##female edu3_trans##female edu4_trans##female wrk5_trans##female wrk1_trans##female wrk2_trans##female wrk3_trans##female wrk4_trans##female  i.reli_c i.kids i.syear, fe vce(cluster pid), if sample_trans==1
est store DE_int_trans




*SHP

do VanDitmars_Shorrocks_Replication_2_SHP.do

*FE and BE analyses

xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
est store CH_int_fe

xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, be
est store CH_int_be

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.year, fe vce(cluster idpers), if female==1
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store CH_female_fe

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.year, fe vce(cluster idpers), if female==0
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store CH_male_fe

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.year, be, if female==1
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store CH_female_be

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.reli_c i.kids i.year, be, if female==0
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store CH_male_be

*transition analysis
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.reli_c i.kids i.year, fe vce(cluster idpers)
capture drop sample_trans
gen sample_trans=1 if e(sample)

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.reli_c i.kids i.year, fe vce(cluster idpers), if female==1 & sample_trans==1

margins, dydx(civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans) post coeflegend
est store CH_female_trans

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans   i.reli_c i.kids i.year, fe vce(cluster idpers), if female==0 & sample_trans==1

margins, dydx(civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans) post coeflegend
est store CH_male_trans

xtreg left_gr civ1_trans##female civ2_trans##female edu3_trans##female edu4_trans##female wrk5_trans##female wrk1_trans##female wrk2_trans##female wrk3_trans##female wrk4_trans##female, fe vce(cluster idpers), if sample_trans==1
est store CH_int_trans

*BHPS/UKHLS

do VanDitmars_Shorrocks_Replication_3_BHPS_UKHLS.do

set more off

rename marital civsta_3 


*FE and BE analysis
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.attend_c i.kids i.year, fe vce(cluster pidp)
est store EN_int_fe

xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.attend_c i.kids i.year, be
est store EN_int_be

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.attend_c i.kids i.year, fe vce(cluster pidp), if female==1
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store EN_female_fe

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.attend_c i.kids i.year, fe vce(cluster pidp), if female==0
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store EN_male_fe

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.attend_c i.kids i.year, be, if female==1
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store EN_female_be

xtreg left_gr i.civsta_3 ib2.edu4 ib3.work3 i.attend_c i.kids i.year, be, if female==0
margins, dydx(work3 edu4 civsta_3) post coeflegend
est store EN_male_be


*transition analysis
xtreg left_gr i.civsta_3##female ib2.edu4##female ib3.work3##female i.attend_c i.kids i.year, fe vce(cluster pidp)
capture drop sample_trans
gen sample_trans=1 if e(sample)

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.attend_c i.kids  i.year, fe vce(cluster pidp), if female==1 & sample_trans==1

margins, dydx(civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans ) post coeflegend
est store EN_female_trans

xtreg left_gr civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans  i.attend_c i.kids  i.year, fe vce(cluster pidp), if female==0 & sample_trans==1

margins, dydx(civ1_trans civ2_trans edu3_trans edu4_trans wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans ) post coeflegend
est store EN_male_trans

xtreg left_gr civ1_trans##female civ2_trans##female edu3_trans##female edu4_trans##female wrk5_trans##female wrk1_trans##female wrk2_trans##female wrk3_trans##female wrk4_trans##female  i.attend_c i.kids i.year, fe vce(cluster pidp), if sample_trans==1
est store EN_int_trans


* Figure 2
// combined plot BE models

coefplot (DE_female_be, label(Women)) (DE_male_be, label(Men)), bylabel("GERMANY") ///
|| (CH_female_be, label(Women)) (CH_male_be, label(Men)), bylabel("SWITZERLAND") ///
|| (EN_female_be, label(Women)) (EN_male_be, label(Men)), bylabel("ENGLAND") ///
||, xscale(lstyle(none)) yscale(lstyle(none)) ///
byopts(cols(3) legend(position(6))) plotregion(lcolor(gs10) lwidth(small)) xline(0) ///
order(0.work3 1.work3 2.work3 1.edu4 3.edu4 4.edu4 1.civsta_3 2.civsta_3) ///
coeflabels (1.civsta_3 = `""Married/Partnership" "Ref. = Unmarried""' 2.civsta_3 = "Divorced/separated" ///
1.edu4 = `""Less than upper second. educ." "Ref. = Upper secondary educ.""'  ///
3.edu4 = "Post-secondary/tertiary vocational" 4.edu4 = "University" 0.work3 = `""Work: other" "Ref. = Housework / Unemployed""'  ///
1.work3 = "FT employed" 2.work3 = "PT employed", notick labgap(2))
graph save "${output}/Figure_2.gph", replace
graph export "${output}/Figure_2.jpg" , replace
graph export "${output}/Figure_2.pdf" , replace

*Figure 3
// combined plot FE models

coefplot (DE_female_fe, label(Women)) (DE_male_fe, label(Men)), bylabel("GERMANY") ///
|| (CH_female_fe, label(Women)) (CH_male_fe, label(Men)), bylabel("SWITZERLAND") ///
|| (EN_female_fe, label(Women)) (EN_male_fe, label(Men)), bylabel("ENGLAND") ///
||, xscale(lstyle(none) range(-.2 .4)) yscale(lstyle(none)) ///
byopts(cols(3) legend(position(6))) plotregion(lcolor(gs10) lwidth(small)) xline(0) ///
order(0.work3 1.work3 2.work3 1.edu4 3.edu4 4.edu4 1.civsta_3 2.civsta_3) ///
coeflabels (1.civsta_3 = `""Married/Partnership" "Ref. = Unmarried""' 2.civsta_3 = "Divorced/separated" ///
1.edu4 = `""Less than upper second. educ." "Ref. = Upper secondary educ.""'  ///
3.edu4 = "Post-secondary/tertiary vocational" 4.edu4 = "University" 0.work3 = `""Work: other" "Ref. = Housework / Unemployed""'  ///
1.work3 = "FT employed" 2.work3 = "PT employed", notick labgap(2))
graph save "${output}/Figure_3.gph", replace
graph export "${output}/Figure_3.jpg" , replace
graph export "${output}/Figure_3.pdf" , replace

*Figure 4
// combined plot transition analysis
coefplot (DE_female_trans, label(Women)) (DE_male_trans, label(Men)), bylabel("GERMANY") ///
|| (CH_female_trans, label(Women)) (CH_male_trans, label(Men)), bylabel("SWITZERLAND") ///
|| (EN_female_trans, label(Women)) (EN_male_trans, label(Men)), bylabel("ENGLAND") ///
||, xline (0) xscale(lstyle(none)) yscale(lstyle(none)) ///
byopts(cols(3) legend(position(6))) ///
order (wrk5_trans wrk1_trans wrk2_trans wrk3_trans wrk4_trans edu3_trans edu4_trans civ1_trans civ2_trans) ///
coeflabels (civ1_trans = "Unmarried -> married" ///
civ2_trans = "Married -> divorced" edu3_trans = "Got post-sec. degree" ///
edu4_trans = "Got univ. degree" wrk5_trans = "Education -> work" ///
wrk1_trans = "Work -> econ. inactive" wrk2_trans = "FT work -> PT work" ///
wrk3_trans = "PT work -> FT work" wrk4_trans = "Econ. inactive -> work" ,notick labgap(2) wrap(30)) ///
headings(civ1_trans = "{bf:Civil status}" edu3_trans = "{bf:Education}" ///
wrk5_trans = "{bf:Labour market}") ///
graphregion(margin(l=0)) plotregion(lcolor(gs10) lwidth(small))
graph save "${output}/Figure_4.gph", replace
graph export "${output}/Figure_4.jpg", replace
graph export "${output}/Figure_4.pdf", replace

*Figure S1
// combined plot interaction effects FE/BE models
coefplot (DE_int_fe, label(interaction term with gender in FE model)) ///
(DE_int_be, label(interaction term with gender in BE model)), bylabel("GERMANY") ///
|| (CH_int_fe, label(interaction term with gender in FE model)) ///
(CH_int_be, label(interaction term with gender in BE model)), bylabel("SWITZERLAND") ///
|| (EN_int_fe, label(interaction term with gender in FE model)) ///
(EN_int_be, label(interaction term with gender in BE model)), bylabel("ENGLAND") ///
||, keep(0.work3#1.female 1.work3#1.female 2.work3#1.female 1.edu4#1.female 3.edu4#1.female 4.edu4#1.female ///
1.civsta_3#1.female 2.civsta_3#1.female) ///
order (0.work3#1.female 1.work3#1.female 2.work3#1.female 1.edu4#1.female 3.edu4#1.female 4.edu4#1.female ///
1.civsta_3#1.female 2.civsta_3#1.female) ///
coeflabels(1.civsta_3#1.female = "Married/partnership * Female" ///
2.civsta_3#1.female = "Divorced/separated * Female" 1.edu4#1.female = "Less than upper sec. ed. * Female" ///
3.edu4#1.female = "Post-sec./ter. voc * Female" 4.edu4#1.female = "University * Female" ///
0.work3#1.female = "Work: other * Female" 1.work3#1.female = "FT employed * Female" ///
2.work3#1.female = "PT employed * Female", notick labgap(2)) ///
xscale(lstyle(none)) xline(0) yscale(lstyle(none)) byopts(cols(3) legend(position(6))) /// 
plotregion(lcolor(gs10) lwidth(small))
graph save "${output}/Figure_S1.gph", replace
graph export "${output}/Figure_S1.jpg" , replace
graph export "${output}/Figure_S1.pdf" , replace


*Figure S2
// combined plot interaction effects transition models
coefplot (DE_int_trans, label(interaction term with gender)), bylabel("GERMANY") ///
|| (CH_int_trans, label(interaction term with gender)), bylabel("SWITZERLAND") ///
|| (EN_int_trans, label(interaction term with gender)), bylabel("ENGLAND") ///
||, keep(1.civ1_trans#1.female 1.civ2_trans#1.female 1.edu3_trans#1.female 1.edu4_trans#1.female ///
1.wrk5_trans#1.female 1.wrk1_trans#1.female 1.wrk2_trans#1.female 1.wrk3_trans#1.female ///
1.wrk4_trans#1.female) ///
order (1.wrk5_trans#1.female 1.wrk1_trans#1.female 1.wrk2_trans#1.female 1.wrk3_trans#1.female ///
1.wrk4_trans#1.female 1.edu3_trans#1.female 1.edu4_trans#1.female 1.civ1_trans#1.female ///
1.civ2_trans#1.female) ///
coeflabels(1.civ1_trans#1.female = "Unmarried -> married" ///
1.civ2_trans#1.female "Married -> divorced" 1.edu3_trans#1.female = "Got post-sec. degree" ///
1.edu4_trans#1.female = "Got univ. degree" 1.wrk5_trans#1.female = "Education -> work" ///
1.wrk1_trans#1.female = "Work -> econ. inactive"  1.wrk2_trans#1.female = "FT work -> PT work" ///
1.wrk3_trans#1.female = "PT work -> FT work" 1.wrk4_trans#1.female = "Econ. inactive -> work", ///
notick labgap(2) wrap (30)) ///
headings(1.civ1_trans#1.female = "{bf:Civil status}" 1.edu3_trans#1.female = "{bf:Education}" ///
1.wrk5_trans#1.female = "{bf:Labour market}") ///
xscale(lstyle(none)) xline(0) yscale(lstyle(none)) byopts(cols (3) legend(position(6))) /// 
plotregion(lcolor(gs10) lwidth(small))
graph save "${output}/Figure_S2.gph", replace
graph export "${output}/Figure_S2.jpg" , replace
graph export "${output}/Figure_S2.pdf" , replace
